
#pragma once
#include "ServerItem.h"
//#include "PropPages.h"

class CServer : public CBaseNodeItem<CServer>
{
	std::vector<CServerItem*> m_vecItems;
public:
	CServer()
	{
		memset(&m_scopeDataItem, 0, sizeof(SCOPEDATAITEM));
		m_scopeDataItem.mask = SDI_STR | SDI_IMAGE | SDI_OPENIMAGE | SDI_PARAM | SDI_CHILDREN;
		m_scopeDataItem.displayname = MMC_CALLBACK;
		m_scopeDataItem.nImage = 0; 		
		m_scopeDataItem.nOpenImage = 1;
		m_scopeDataItem.lParam = (LPARAM) this;
		
		memset(&m_resultDataItem, 0, sizeof(RESULTDATAITEM));

		for(int i=0; i<10; i++)
		{
			char buff[100];
			itoa(i, buff, 10);
			CComBSTR bstr(buff);
			
			m_vecItems.push_back(new CServerItem(bstr.Detach()));
		}
	}
	
	~CServer()
	{
		for(int i=0; i<m_vecItems.size(); i++)
			delete m_vecItems[i];
	}


	STDMETHOD(GetResultViewType)(LPOLESTR *ppViewType,long *pViewOptions)
	{
		*ppViewType = NULL;
		*pViewOptions = MMC_VIEW_OPTIONS_NONE;
		return S_FALSE;
	}

	//STDMETHOD(CreatePropertyPages)(LPPROPERTYSHEETCALLBACK lpProvider,long handle, IUnknown* pUnk,
	//						DATA_OBJECT_TYPES type)
	//{
	//	//if (type == CCT_SCOPE || type == CCT_RESULT)
	//	//{
	//	//	CSimplePage* pPage = new CSimplePage(this, handle, true, _T("Simple"));
	//	//	HRESULT hr = lpProvider->AddPage(pPage->Create());
	//	//	// The second parameter  to the property page class constructor
	//	//	// should be true for only one page.
	//	//	return S_OK;
	//	//}
	//	return E_UNEXPECTED;
	//}

	STDMETHOD(QueryPagesFor)(DATA_OBJECT_TYPES type)
	{
		if (type == CCT_SCOPE || type == CCT_RESULT)
			return S_OK;
		return S_FALSE;
	}

	HRESULT OnSelect(IConsole *spConsole, IComponent* pComponent)
	{
		IConsoleVerb *pConsoleVerb;
		HRESULT hr = spConsole->QueryConsoleVerb(&pConsoleVerb);
		_ASSERT(SUCCEEDED(hr));
		hr = pConsoleVerb->SetVerbState(MMC_VERB_RENAME, ENABLED, TRUE);
		_ASSERT(SUCCEEDED(hr));
		hr = pConsoleVerb->SetVerbState(MMC_VERB_PROPERTIES, ENABLED, TRUE);
		_ASSERT(SUCCEEDED(hr));
		pConsoleVerb->Release();
		
		return S_OK;
	}

	LPOLESTR GetResultPaneColInfo(int nCol)
	{
	   switch (nCol)
	   {
	   case 0:
		  return m_bstrDisplayName;
	   case 1:
		  return OLESTR("Column X");
	   }

	   return OLESTR("Override GetResultPaneColInfo");
	}
	HRESULT OnShow(IConsole *pConsole, BOOL bShow)
	{
		HRESULT hr = S_FALSE;
		if(bShow)
		{        
			CComQIPtr<IResultData, &IID_IResultData> spResultData(pConsole);
			CComQIPtr<IHeaderCtrl, &IID_IHeaderCtrl> spHeaderCtrl(pConsole);
			//spResultData->SetDescBarText(OLESTR("Bleh"));
			//spResultData->SetViewMode(LVS_LIST);
			HRESULT hr = spResultData->DeleteAllRsltItems();
			/*
			CComPtr<IDataObject, &IID_IDataObject> spDataObject;
			GetDataObject(&spDataObject, CCT_SCOPE);
			pConsole->UpdateAllViews(spDataObject, 0, 0);
			*/
			hr = spHeaderCtrl->InsertColumn( 0, L"Col 1", 0,  MMCLV_AUTO);

		    for(int i=0; i<m_vecItems.size(); i++)
			{
				hr=spResultData->InsertItem(&m_vecItems[i]->m_resultDataItem);
				_ASSERT( SUCCEEDED(hr) );
			}
		}
		return S_FALSE;
	}	 

	//HRESULT OnShowContextHelp(IDisplayHelp *pDisplayHelp);
};
